﻿namespace MefContrib.Models.Provider.Tests
{
    using System;
    using System.Reflection;
    using NUnit.Framework;

    [TestFixture]
    public class MemberInfoServicesTests
    {

#if !SILVERLIGHT

        [Test]
        public void GetMemberInfoShouldReturnMemberIfMemberNameIsSupplied()
        {
            MemberInfo member =
                MemberInfoServices.GetMemberInfo("MefContrib.Models.Provider.Tests.FakePropertyPart, MefContrib.Models.Provider.Tests", "NonStaticReadWrite");

            Assert.IsNotNull(member);
        }

        [Test]
        public void GetMemberInfoShouldReturnTypeIfMemberNameNotIsSupplied()
        {
            Type type =
                MemberInfoServices.GetMemberInfo("MefContrib.Models.Provider.Tests.FakePropertyPart, MefContrib.Models.Provider.Tests", null) as Type;

            Assert.IsNotNull(type);
        }

#else
        [Test]
        public void GetMemberInfoShouldReturnMemberIfMemberNameIsSupplied()
        {
            MemberInfo member =
                MemberInfoServices.GetMemberInfo("MefContrib.Models.Provider.Tests.FakePropertyPart, MefContrib.Models.Provider.Tests, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "NonStaticReadWrite");

            Assert.IsNotNull(member);
        }

        [Test]
        public void GetMemberInfoShouldReturnTypeIfMemberNameNotIsSupplied()
        {
            Type type =
                MemberInfoServices.GetMemberInfo("MefContrib.Models.Provider.Tests.FakePropertyPart, MefContrib.Models.Provider.Tests, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", null) as Type;

            Assert.IsNotNull(type);
        }

#endif

        [Test, ExpectedException(typeof(ArgumentNullException))]
        public void GetMemberInfoShouldThrowExceptionIfTypeNameIsNull()
        {
            MemberInfo member =
                MemberInfoServices.GetMemberInfo(null, null);
        }

        [Test, ExpectedException(typeof(ArgumentException))]
        public void GetMemberInfoShouldThrowExceptionIfTypeNameIsEmpty()
        {
            MemberInfo member =
                MemberInfoServices.GetMemberInfo(string.Empty, null);
        }
    }
}